home *** CD-ROM | disk | FTP | other *** search
/ Ray Dream Studio 5 / Ray Dream.iso / pc / DreamSDK / Windows / SAMPLES / SHADER / SHDR / RAINBOW.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-11  |  4.0 KB  |  109 lines

  1. // Copyright (c)1995 Ray Dream, Inc. All Rights Reserved.
  2. /* $Id: Rainbow.cpp 1.3 1997/04/05 02:41:56 damien Exp $ */
  3. //
  4. // Implementation of the Rainbow Shader
  5. //
  6.  
  7.  
  8. #ifndef __RAINBOW__
  9. #include "Rainbow.h"
  10. #endif
  11.  
  12. #undef INTERFACE
  13. #define INTERFACE RainbowShader
  14.  
  15. // Rainbow Constructor :
  16. RainbowShader::RainbowShader() {
  17.   RainbowPublicData.fIntensity = 100; // Default Value of the rainbow's intensity (100%)
  18.   RainbowPublicData.fModeLocalOrGlobal = 1 ; // Default is Local (0 : Global)
  19.   };
  20.   
  21. RainbowShader::~RainbowShader() {
  22.     global_count_Obj--; // used by the DLL to know if it can be unloaded
  23.                         // the variable is global and defines in "Shadrdll.cpp"
  24.     }
  25.                         
  26. // How to Clone the Rainbow
  27. I3DExtension* RainbowShader::Clone(THIS) {
  28.   RainbowShader* theClone = new RainbowShader;  // Create New Rainbow
  29.   CopyData(theClone);                                                        // Copy Data in the new Rainbow
  30.     theClone->AddRef();
  31.   return theClone;
  32.   }
  33.   
  34. short RainbowShader::GetResID(THIS) {
  35.   return 129; // Ressource ID for the Shell
  36.   }
  37.  
  38. // Give a pointer to the public data that the shell can modify
  39. void* RainbowShader::GetExtensionDataBuffer(THIS) {
  40.   return ((void*) &(RainbowPublicData));
  41.   }                               
  42.   
  43. // Compare two Shader
  44. BOOLEAN RainbowShader::IsEqualTo(THIS_ I3DExShader* aShader) {
  45.   return ((RainbowPublicData.fIntensity==((RainbowShader*)aShader)->RainbowPublicData.fIntensity)
  46.          &&(RainbowPublicData.fModeLocalOrGlobal==((RainbowShader*)aShader)->RainbowPublicData.fModeLocalOrGlobal));
  47.   }                                                                                                     
  48.   
  49.   
  50. BOOLEAN RainbowShader::DependsOnAppliedExtent(THIS) {
  51.   return FALSE; // The Rainbow doesn't use the UV Space but only the Normal Vectors
  52.   }
  53.   
  54. HRESULT RainbowShader::DoShade(THIS_ ShadingInOut* /*theShadingIO*/, ShadingElem* /*theShadingElem*/)    {
  55.   return ResultFromScode(E_NOTIMPL);
  56.   }
  57.                   
  58. ULONG RainbowShader::GetPreferredOutput(THIS) {
  59.   return kUsesGetColor; // Tell the Shell that this Shader is a Color Shader
  60.   }
  61.  
  62. HRESULT RainbowShader::GetValue(THIS_ NUM3D* result, ShadingIn* theShadingIn, ShadingElem* theShadingElem) {
  63.     return ResultFromScode(E_NOTIMPL);
  64.   }
  65.  
  66. // This shader returns a Color defined by a Vector in the RGB Cube                     
  67. HRESULT RainbowShader::GetColor(THIS_ COLOR3D* result, ShadingIn* theShadingIn, ShadingElem* theShadingElem)    {
  68.     NUM3D temp=RainbowPublicData.fIntensity;
  69.     temp/=100.0;
  70.   result->Mode = 0; // RGB color mode
  71.   if (RainbowPublicData.fModeLocalOrGlobal==1) {
  72.     result->R    = (((theShadingIn->fNormalLoc[0])*temp)/2)+0.5;
  73.       result->G         = (((theShadingIn->fNormalLoc[1])*temp)/2)+0.5;
  74.       result->B    = (((theShadingIn->fNormalLoc[2])*temp)/2)+0.5;
  75.       }
  76.   else {
  77.       result->R    = (((theShadingIn->fNormal[0])*temp)/2)+0.5;
  78.       result->G         = (((theShadingIn->fNormal[1])*temp)/2)+0.5;
  79.       result->B    = (((theShadingIn->fNormal[2])*temp)/2)+0.5;
  80.     }
  81.   return NOERROR;
  82.   }
  83.  
  84. HRESULT RainbowShader::GetVector(THIS_ VECTOR3D* result, ShadingIn* theShadingIn, ShadingElem* theShadingElem) {
  85.     return ResultFromScode(E_NOTIMPL);
  86.     }
  87.  
  88. // Set the flags of the Shader
  89. HRESULT RainbowShader::GetShadingFlags(THIS_ ShadingFlags* theFlags)    {
  90.   theFlags->fNeedsNormalLoc = TRUE;
  91.   theFlags->fNeedsNormal    = TRUE;
  92.   theFlags->fCallOnce = FALSE;
  93.   return NOERROR;
  94.   }
  95.                               
  96. // Function to Clone the Object
  97. void RainbowShader::CopyData(COMShader* dest) {
  98.   COMShader::CopyData(dest); // Copy Data of the inherited object (Shader)
  99.   ((RainbowShader*)dest)->RainbowPublicData=RainbowPublicData; // Copy Public Data
  100.   }
  101.                                                               
  102. // If you don't use a resource that can give the type of the different
  103. // data in the CheckerShaderPublicData you have to give a pointer on this
  104. // Properties Map
  105. ExtensionDataMap* RainbowShader::GetExtensionDataMap(THIS) {
  106.   return NULL;
  107.   }
  108.   
  109.